package com.itheima.cglib;

import com.itheima.proxy.IProducer;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Client {



    public static void main(final String[] args) {
        final Producer producer=new Producer();
        /**
         * 基于子类的动态代理
         * Enhancer.create
         * 被代理类不能是最终类
         */
        Producer p= (Producer) Enhancer.create(producer.getClass(), new MethodInterceptor() {
            public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

               return method.invoke(o,objects[0]);
            }
        });
        p.saleProduct(1000f);
    }
}
